package transport

import (
	"context"
	"encoding/json"
	"net/http"
	"gowork/studentGoKit/server/endpoint"
	"fmt"
	//"github.com/gorilla/mux"
)

func DecodeStudentInsertOrUpdateRequest(ctx context.Context, r *http.Request)(interface{}, error){

	r.ParseForm()
	id := r.Form.Get("id")
	name :=  r.Form.Get("name")
	birth :=  r.Form.Get("birth")
	sex :=  r.Form.Get("sex")
	
	fmt.Println("参数", id, name, birth, sex)

	return endpoint.SudentRequest{
		Id : id,
		Name : name,
		Birth : birth,
		Sex : sex,
	}, nil
}

func DecodeStudentDeleteRequest(ctx context.Context, r *http.Request)(interface{}, error){

	r.ParseForm()
	name :=  r.Form.Get("name")

	// vars := mux.Vars(r)
	// name, _:= vars["name"]

	return endpoint.StudentNameRequest{
		Name: name,
	}, nil
}

func DecodeStudentQueryRequest(ctx context.Context, r *http.Request)(interface{}, error){

	return endpoint.SudentNilRequest{

	}, nil

}

func EncodeStudentResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error{
	w.Header().Set("Content-type", "application/json")
	return json.NewEncoder(w).Encode(response)
}
